import request from "@/util/request";
import { ChatGroup } from "@/types/contact";

// 获取群聊列表
export const getGroupListApi = (userId: number) => {
  return request({
    url: "/group/list",
    method: "get",
    params: { userId },
  });
};

// 创建群聊
export const createGroupApi = (
  userId: number,
  groupData: Partial<ChatGroup>
) => {
  return request({
    url: "/group/create",
    method: "post",
    params: { userId },
    data: groupData,
  });
};

// 更新群聊信息
export const updateGroupApi = (
  groupId: number,
  groupData: Partial<ChatGroup>
) => {
  return request({
    url: `/group/update`,
    method: "put",
    params: { groupId },
    data: groupData,
  });
};

// 解散群聊
export const dismissGroupApi = (groupId: number, userId: number) => {
  return request({
    url: `/group/dismiss`,
    method: "delete",
    params: { groupId, userId },
  });
};

// 获取群成员列表
export const getGroupMembersApi = (groupId: number) => {
  return request({
    url: `/group/member/list`,
    method: "get",
    params: { groupId },
  });
};

// 跟你用户id查询群成员
export const getByUserId = (groupId: number, userId: number) => {
  return request({
    url: `/group/member/getByUserId`,
    method: "get",
    params: { groupId, userId },
  });
};

// 踢出群成员
export const kickMemberApi = (
  groupId: number,
  operatorId: number,
  targetId: number
) => {
  return request({
    url: `/group/member/kick`,
    method: "delete",
    params: { groupId, operatorId, targetId },
  });
};

// 禁言群成员
export const muteMemberApi = (
  groupId: number,
  operatorId: number,
  targetId: number,
  duration: number
) => {
  return request({
    url: `/group/member/mute`,
    method: "post",
    params: { groupId, operatorId, targetId, duration },
  });
};

// 解除禁言
export const unmuteMemberApi = (
  groupId: number,
  operatorId: number,
  targetId: number
) => {
  return request({
    url: `/group/member/unmute`,
    method: "post",
    params: { groupId, operatorId, targetId },
  });
};

// 设置管理员
export const setAdminApi = (
  groupId: number,
  operatorId: number,
  targetId: number
) => {
  return request({
    url: `/group/member/set-admin`,
    method: "post",
    params: { groupId, operatorId, targetId },
  });
};

// 更新群信息
export const updateGroupInfoApi = (
  groupId: number,
  groupData: Partial<ChatGroup>
) => {
  return request({
    url: `/group/update`,
    method: "put",
    params: { groupId },
    data: groupData,
  });
};

// 解散群聊
export const dissolveGroupApi = (groupId: number, userId: number) => {
  return request({
    url: `/group/dismiss`,
    method: "delete",
    params: { groupId, userId },
  });
};

// 退出群聊
export const quitGroupApi = (groupId: number, userId: number) => {
  return request({
    url: `/group/exit`,
    method: "delete",
    params: { groupId, userId },
  });
};

// 更新群内昵称
export const updateMemberNicknameApi = (
  groupId: number,
  userId: number,
  nickname: string
) => {
  return request({
    url: `/group/member/update-nickname`,
    method: "put",
    params: { groupId, userId },
    data: { nickname },
  });
};
